<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<form action="">
    用户名
    <input type="text" name="" id="uname">
    密码
    <input type="text" name="" id="pwd">
    验证码
    <img src="http://kg.zhaodashen.cn/v1/public/captcha.jsp" alt="">
    <input type="text" name="" id="captcha">

    勾选7天免登录 <input type="checkbox" >
    <input type="submit" value="登录">
</form>

<script src="axios.js"></script>

<script>
let dlBtnObj = document.querySelector('input[type=submit]')
dlBtnObj.onclick = async function(evt) {
    let e = evt || window.event
    e.preventDefault()
    let uname = document.querySelector('#uname').value
    let pwd = document.querySelector('#pwd').value
    let captcha = document.querySelector('#captcha').value
    let res = await post('http://kg.zhaodashen.cn/v1/public/login.jsp', `uname=${uname}&pwd=${pwd}&captcha=${captcha}`)

    if(res.meta.state == 200) {
        alert(res.meta.msg)
        if(document.querySelector('input[type=checkbox]').checked) {
            localStorage.setItem('uname',res.data.uname)
            localStorage.setItem('token',res.data.token)
            localStorage.setItem('expires', (new Date).getTime()+ 1000*60*60*24*7)
        } else {
            localStorage.setItem('uname',res.data.uname)
            localStorage.setItem('token',res.data.token)
        }
        location.href = './member.html'
    } else {
        alert(res.meta.msg)
    }
}

document.querySelector('img').onclick = function() {
    this.src = 'http://kg.zhaodashen.cn/v1/public/captcha.jsp?t='+(new Date).getTime()
}

</script>